package com.zhq.service;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zhq.Interface.user.service.IUserService;
import com.zhq.user.entity.User;


public class UserServiceTest {
	private IUserService userService;
	private static ClassPathXmlApplicationContext ctx;
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    	ctx = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","com/zhq/user/user-beans.xml"});
    }
    
    
    @Before
    public void setUp() throws Exception {
    	userService =(IUserService)ctx.getBean("userService");
    }
	@Test
	public void testIsExist() {
		System.out.println(userService.isExist(2));
	}
	
	@Test
	public void testFetchUsers() {
		System.out.println(userService.fetchUsers());
	}
	
	@Test
	public void testAddUser() {
		User user = new User();
		userService.addUser(user);
	}
	
	@Test
	public void testDeleteUser() {
		userService.deleteUser(3);
	}
	
	@Test
	public void testFetchUserById() {
		System.out.println(userService.fetchUsers());
	}
	
	@Test
	public void testModifyUser() {
		User user = userService.fetchUserById(2);
		user.setPassword("pwd");
		userService.modifyUser(user);
	}
}
